package Sort;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:13
 */
public class InsertSort {
        public static void main(String[] args){
            int[] arr = {1,2,5,3,6};
            sort(arr);
            System.out.println(Arrays.toString(arr));
        }

        public static void sort(int[] arr){
            //首先定义一个比较标准值，开始时就是当前值
            for (int i = 0; i < arr.length; i++){
                int valueIndex = arr[i];
                int Index = i - 1;
                while (Index >= 0 && arr[Index] > valueIndex){
                    arr[Index+1] = arr[Index];
                    Index--;
                }
                if (Index + 1 != i)
                arr[Index + 1] = valueIndex;
            }
        }
}
